package com.cyx.filter;

import javax.servlet.*;
import java.io.IOException;

public class CharsetEncodingFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding("UTF-8");
        servletResponse.setCharacterEncoding("UTF-8");
        servletResponse.setContentType("text/html;charset=utf-8");
        System.out.println("CharsetEncodingFilter 前");
        filterChain.doFilter(servletRequest,servletResponse);
        System.out.println("CharsetEncodingFilter 后");
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("CharsetEncodingFilter 初始化");
        System.out.println(filterConfig);
    }

    @Override
    public void destroy() {
        System.out.println("CharsetEncodingFilter 销毁");
    }
}
